<!DOCTYPE html>
<html lang="${LANG}">

<head>
    <meta charset="UTF-8" />
    <title>QBT_TR(Upload local torrent)QBT_TR[CONTEXT=HttpServer]</title>
    <link rel="stylesheet" href="css/style.css?v=${CACHEID}" type="text/css" />
    <link rel="stylesheet" href="css/Window.css?v=${CACHEID}" type="text/css" />
    <script src="scripts/lib/mootools-1.2-core-yc.js"></script>
    <script src="scripts/download.js?v=${CACHEID}"></script>
</head>

<body>
    <iframe id="upload_frame" name="upload_frame" class="invisible" src="about:blank"></iframe>
    <form action="api/v2/torrents/add" enctype="multipart/form-data" method="post" id="uploadForm" style="text-align: center;" target="upload_frame" autocorrect="off" autocapitalize="none">
        <div style="margin-top: 25px; display: inline-block; border: 1px solid lightgrey; border-radius: 4px;">
            <input type="file" id="fileselect" name="fileselect[]" multiple="multiple" />
        </div>
        <fieldset class="settings" style="border: 0; text-align: left; margin-top: 12px;">
            <table style="margin: auto;">
                <tr>
                    <td>
                        <label for="autoTMM">QBT_TR(Torrent Management Mode:)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
                    </td>
                    <td>
                        <select id="autoTMM" name="autoTMM" onchange="qBittorrent.Download.changeTMM(this)">
                            <option selected value="false">Manual</option>
                            <option value="true">Automatic</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="savepath">QBT_TR(Save files to location:)QBT_TR[CONTEXT=HttpServer]</label>
                    </td>
                    <td>
                        <input type="text" id="savepath" name="savepath" style="width: 16em;" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="rename">QBT_TR(Rename torrent)QBT_TR[CONTEXT=HttpServer]</label>
                    </td>
                    <td>
                        <input type="text" id="rename" name="rename" style="width: 16em;" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="category">QBT_TR(Category:)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
                    </td>
                    <td>
                        <div class="select-watched-folder-editable">
                            <select id="categorySelect" onchange="qBittorrent.Download.changeCategorySelect(this)">
                                <option selected value="\other"></option>
                            </select>
                            <input name="category" type="text" />
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="startTorrent">QBT_TR(Start torrent)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
                    </td>
                    <td>
                        <input type="hidden" id="startTorrentHidden" name="paused" />
                        <input type="checkbox" id="startTorrent" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="skip_checking">QBT_TR(Skip hash check)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
                    </td>
                    <td>
                        <input type="checkbox" id="skip_checking" name="skip_checking" value="true" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="contentLayout">QBT_TR(Content layout:)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
                    </td>
                    <td>
                        <select id="contentLayout" name="contentLayout">
                            <option selected value="Original">QBT_TR(Original)QBT_TR[CONTEXT=AddNewTorrentDialog]</option>
                            <option value="Subfolder">QBT_TR(Create subfolder)QBT_TR[CONTEXT=AddNewTorrentDialog]</option>
                            <option value="NoSubfolder">QBT_TR(Don't create subfolder)QBT_TR[CONTEXT=AddNewTorrentDialog]</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="sequentialDownload">QBT_TR(Download in sequential order)QBT_TR[CONTEXT=TransferListWidget]</label>
                    </td>
                    <td>
                        <input type="checkbox" id="sequentialDownload" name="sequentialDownload" value="true" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="firstLastPiecePrio">QBT_TR(Download first and last pieces first)QBT_TR[CONTEXT=TransferListWidget]</label>
                    </td>
                    <td>
                        <input type="checkbox" id="firstLastPiecePrio" name="firstLastPiecePrio" value="true" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="dlLimitText">QBT_TR(Limit download rate)QBT_TR[CONTEXT=HttpServer]</label>
                    </td>
                    <td>
                        <input type="hidden" id="dlLimitHidden" name="dlLimit" />
                        <input type="text" id="dlLimitText" style="width: 16em;" placeholder="KiB/s" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="upLimitText">QBT_TR(Limit upload rate)QBT_TR[CONTEXT=HttpServer]</label>
                    </td>
                    <td>
                        <input type="hidden" id="upLimitHidden" name="upLimit" />
                        <input type="text" id="upLimitText" style="width: 16em;" placeholder="KiB/s" />
                    </td>
                </tr>
            </table>
            <div id="submitbutton" style="margin-top: 30px; text-align: center;">
                <button type="submit" style="font-size: 1em;">QBT_TR(Upload Torrents)QBT_TR[CONTEXT=HttpServer]</button>
            </div>
        </fieldset>
    </form>
    <script>
        'use strict';

        let submitted = false;

        $('uploadForm').addEventListener("submit", function() {
            $('startTorrentHidden').value = $('startTorrent').checked ? 'false' : 'true';

            $('dlLimitHidden').value = $('dlLimitText').value.toInt() * 1024;
            $('upLimitHidden').value = $('upLimitText').value.toInt() * 1024;

            $('upload_spinner').style.display = "block";
            submitted = true;
        });

        $('upload_frame').addEventListener("load", function() {
            if (submitted)
                window.parent.closeWindows();
        });
    </script>
    <div id="upload_spinner" class="mochaSpinner"></div>
</body>

</html>
